package com.ruoyi.procategory.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.procategory.domain.ProCategory;
import com.ruoyi.procategory.service.IProCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 商品分类/类别Controller
 * 
 * @author ruoyi
 * @date 2025-02-12
 */
@RestController
@RequestMapping("/procategory/procategory")
public class ProCategoryController extends BaseController
{
    @Autowired
    private IProCategoryService proCategoryService;

    /**
     * 查询商品分类/类别列表
     */
    @PreAuthorize("@ss.hasPermi('procategory:procategory:list')")
    @GetMapping("/list")
    public AjaxResult list(ProCategory proCategory)
    {
        List<ProCategory> list = proCategoryService.selectProCategoryList(proCategory);
        return success(list);
    }

    /**
     * 导出商品分类/类别列表
     */
    @PreAuthorize("@ss.hasPermi('procategory:procategory:export')")
    @Log(title = "商品分类/类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProCategory proCategory)
    {
        List<ProCategory> list = proCategoryService.selectProCategoryList(proCategory);
        ExcelUtil<ProCategory> util = new ExcelUtil<ProCategory>(ProCategory.class);
        util.exportExcel(response, list, "商品分类/类别数据");
    }

    /**
     * 获取商品分类/类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('procategory:procategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(proCategoryService.selectProCategoryById(id));
    }

    /**
     * 新增商品分类/类别
     */
    @PreAuthorize("@ss.hasPermi('procategory:procategory:add')")
    @Log(title = "商品分类/类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProCategory proCategory)
    {
        return toAjax(proCategoryService.insertProCategory(proCategory));
    }

    /**
     * 修改商品分类/类别
     */
    @PreAuthorize("@ss.hasPermi('procategory:procategory:edit')")
    @Log(title = "商品分类/类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProCategory proCategory)
    {
        return toAjax(proCategoryService.updateProCategory(proCategory));
    }

    /**
     * 删除商品分类/类别
     */
    @PreAuthorize("@ss.hasPermi('procategory:procategory:remove')")
    @Log(title = "商品分类/类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(proCategoryService.deleteProCategoryByIds(ids));
    }
}
